﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Windows.Forms;

namespace luanvanFinal
{
    class clsLine
    {
        int idProject;
        String clsUser;
        String clsSys;
        String clsDesign;
        String note;
        public int IdProject
        {
            get { return idProject; }
            set { idProject = value; }
        }
        public String ClsUser
        {
            get { return clsUser; }
            set { clsUser = value; }
        }
        public String ClsSys
        {
            get { return clsSys; }
            set { clsSys = value; }
        }
        public String ClsDesign
        {
            get { return clsDesign; }
            set { clsDesign = value; }
        }
        public String Note
        {
            get { return note; }
            set { note = value; }
        }
        public clsLine()
        {
            idProject = 0;
            clsUser = "";
            clsSys = "";
            clsDesign = "";
            note = "";
        }

        public void insertLine()
        {
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            try
            {
                SqlCommand sqlcmd = new SqlCommand("insertLine", ketnoi.Connection);
                sqlcmd.CommandType = CommandType.StoredProcedure;
                sqlcmd.Parameters.Add("@idProject", SqlDbType.Int).Value = this.idProject;
                sqlcmd.Parameters.Add("@clsUser", SqlDbType.NVarChar).Value = this.clsUser;
                sqlcmd.Parameters.Add("@clsSystem", SqlDbType.NVarChar).Value = this.clsSys;
                sqlcmd.Parameters.Add("@clsDesign", SqlDbType.NVarChar).Value = this.clsDesign;
                sqlcmd.Parameters.Add("@note", SqlDbType.NVarChar).Value = this.note;
                sqlcmd.ExecuteNonQuery();
                MessageBox.Show("You have grouped success !!!","Success",MessageBoxButtons.OK,MessageBoxIcon.Information);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Dữ liệu đã tồn tại hoặc không hợp lệ!!!" + ex.ToString(), "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            ketnoi.closeConnection();
        }

        public static DataTable getDataLine(String strSQL)
        {
            
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ketnoi.closeConnection();
            return dt;
        }

        public DataTable getAllDataVersion(int idProject)
        {
            String strSQL = "select * from line where idProject = '"+idProject+"' ";
            clsConnect ketnoi = new clsConnect();
            ketnoi.openConnection();
            SqlDataAdapter da = new SqlDataAdapter(strSQL, ketnoi.Connection);
            DataTable dt = new DataTable();
            da.Fill(dt);
            ketnoi.closeConnection();
            return dt;
        }
    }
}
